var sess = sessionStorage.getItem("session");
var FilterArea;
var Search;
if (!sess) {
	window.top.location = "../../login.html";
}
$(document).ready(function() {
	$('#WarningArea').combobox({
		url: IP + "GetDepartmentInfo?callback=?",
		valueField: 'id',
		textField: 'text',
		editable: false,
	});
	var sDate = getThrBeforeDate();
	var eDate = getNowFormatDate();
	var sDatex = sDate.substr(0, 10);
	var eDatex = eDate.substr(0, 10);
	$('#sDate').datetimebox('setValue', sDate);
	$('#eDate').datetimebox('setValue', eDate);
	$("#WarningGrid").jqGrid({
		url: IP + "QueryWaingInfo?callback=?&session=" + session + "&sDate=" + sDatex + "&eDate=" + eDatex,
		mtype: "Get",
		datatype: "jsonp",
		colModel: [{
			label: '序号',
			sorttype: 'integer',
			name: 'id',
			key: true,
			width: 50,
			hidden: true
		}, {
			label: '设备编码',
			name: 'deviceid',
			sopt: ['eq']
		}, {
			label: '操作',
			sopt: ['eq'],
			name: 'operate'
		}, {
			label: '告警名称',
			sopt: ['eq'],
			name: 'wName'
		}, {
			label: '告警类型',
			sopt: ['eq'],
			name: 'wType'
		}, {
			label: '告警条件',
			sopt: ['eq'],
			name: 'wCondition'
		}, {
			label: 'offTime',
			sopt: ['eq'],
			name: 'offTime'
		}, {
			label: 'cTime',
			sopt: ['eq'],
			name: 'cTime'
		}, {
			label: '告警状态',
			sopt: ['eq'],
			name: 'wState'
		}],
		loadonce: true,
		height: 350,
		rowNum: 17,
		rownumbers: true,
		autowidth: true,
		pagerpos: 'center',
		page: 1,
		viewrecords: true,
		pgbuttons: true,
		pginput: true,
		loadtext: '正在加载数据',
		pager: "#WarningGridPager"
	});

	$(window).bind('resize', function() {
		$("#WarningGrid").setGridWidth($(window).width() * 0.96);
		$("#WarningGrid").setGridHeight($(window).height() * 0.6);
	});

	Search = function() {
		sDateS = $('#sDate').datetimebox('getValue').substr(0, 10);
		eDateS = $('#eDate').datetimebox('getValue').substr(0, 10);
		console.log(eDateS);
		if (DateRight(sDateS, eDateS)) {
			var myurl = IP + "QueryWaingInfo=?&session=" + session + "&sDate=" + sDateS + "&eDate=" + eDateS;
			$('#QueryFtpUploadGrid').jqGrid('setGridParam', {
				url: myurl,
				type: 'Get',
				datatype: "jsonp",
			}).trigger('reloadGrid');
			console.log(myurl);
			insertopertlog('告警管理', '历史告警查询', '查询', '', '');

		} else {
			$.messager.show({
				title: '提醒',
				msg: '请选择正确的时间范围！',
				timeout: 1300,
				showType: 'slide',
				style: {
					right: '',
					bottom: ''
				}
			});
		}
	}
	ExportFile = function() {
		var title = "历史告警";
		getXlsFromTbl('WarningGrid', 'gridtable', title, true);
	}
	FilterArea = function() {
		var ValueArea = $("#WarningArea").combobox('getText');
		//		console.log(ValueArea);
		//		$('#WarningAreaHiden').val(ValueArea);
		if (timer) {
			clearTimeout(timer);
		}
		timer = setTimeout(function() {
			$("#WarningGrid").jqGrid('filterInput', ValueArea);
		}, 0);
	}
	FilterType = function() {
		var ValueType = $("#WarningArea").combobox('getValue');
		//		console.log(ValueArea);
		//		$('#WarningAreaHiden').val(ValueArea);
		if (timer) {
			clearTimeout(timer);
		}
		timer = setTimeout(function() {
			$("#WarningGrid").jqGrid('filterInput', ValueType);
		}, 0);
	}

	$("#KeyWord").on("keyup", function() {

		var thisvalue = $("#KeyWord").textbox('getValue');
		if (timer) {
			clearTimeout(timer);
		}
		timer = setTimeout(function() {
			//timer = null;
			$("#WarningGrid").jqGrid('filterInput', thisvalue);
		}, 0);
	});

})